/*
 * MenuGameState.java
 *
 * Created on Jul 9, 2007, 6:39:34 PM
 *
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.gamestate;

import com.jmex.awt.swingui.JMEDesktopState;
import java.util.concurrent.Callable;
import com.jme.input.MouseInput;
import com.jme.util.GameTaskQueueManager;
import com.jmex.awt.swingui.JMEDesktopState;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import java.util.concurrent.Callable;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import kanjitori.KanjiTori;
import kanjitori.util.JMEDesktopUtil;

import static kanjitori.util.Bundle.*;

/**
 *
 * @author DGronau
 */
public class MenuGameState extends JMEDesktopState {
    
    final static int N = 6; //number of buttons
    final static String[] CAPTIONS = {
        "menu_loadLesson", 
        "menu_loadMap",
        "menu_videoSettings",
        "menu_inputOptions",
        "menu_startGame",
        "menu_quit"
    };

    public MenuGameState() {
        GameTaskQueueManager.getManager().update(new Callable<Object>() {

            public Object call() throws Exception {
                initGraphics();
                return null;
            }
        });
    }

    private void initGraphics() {
        JDesktopPane jDesktop = getDesktop().getJDesktop();
        JMEDesktopUtil.init(jDesktop); 
        
        Dimension size = new Dimension(0, 0);
        JButton[] button = new JButton[N];
        for (int i = 0; i < N; i++) {
            button[i] = new JButton(getString(CAPTIONS[i]));
            jDesktop.add(button[i]);
        }
        JMEDesktopUtil.maxSize(button);
        for (int i = 0; i < N; i++) {
            JMEDesktopUtil.pos(button[i], 0, (int) (50 * (i - (N-1)/2.0)), JMEDesktopUtil.H.CENTER, JMEDesktopUtil.V.CENTER);
        }
        
        button[2].addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae) {
                KanjiTori.setVideoGameState();
            }
        });
        
        button[3].addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae) {
                KanjiTori.setInputGameState();
            }
        });

        button[5].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                KanjiTori.shutdown();
            }
        });

        button[4].setEnabled(false);
        MouseInput.get().setCursorVisible(true);
    }
}
